package com.bianmaba.ehcache.controller;

import com.bianmaba.ehcache.model.Role;
import com.bianmaba.ehcache.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @program: samples
 * @description:
 * @author: Chenjiabin
 * @create: 2019/9/9 16:07
 **/
@RestController

@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleRepository roleRepository;

    @RequestMapping("get_by_id")
    public Role getById(String id) {
        Optional<Role> qq = roleRepository.findById(id);
        return qq.get();
    }

    @RequestMapping("query")
    @Cacheable(value = "testSystemCache", key = "'id='+#id")
    public List<Role> query(String id) {
        List<Role> qq = roleRepository.findAll();
        return qq;
    }
}
